package com.yami.shop.multishop.controller;

import com.yami.shop.service.WxMaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 微信小程序控制器
 */
@RestController
@RequestMapping("/wxma")
@Api(tags = "微信小程序接口", description = "提供微信小程序相关接口")
public class WxMaController {
    
    @Resource
    private WxMaService wxMaService;
    
    /**
     * 获取小程序码（适用于需要的码数量较少的业务场景）
     */
    @GetMapping("/getwxacode")
    @ApiOperation(value = "获取小程序码", notes = "获取小程序码，适用于需要的码数量较少的业务场景")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "page", value = "跳转页面路径", required = true, dataType = "String", paramType = "query", example = "pages/index/index"),
        @ApiImplicitParam(name = "scene", value = "场景参数", required = true, dataType = "String", paramType = "query", example = "id=1&type=product"),
        @ApiImplicitParam(name = "width", value = "二维码宽度", dataType = "Integer", paramType = "query", example = "430"),
        @ApiImplicitParam(name = "autoColor", value = "自动配置线条颜色", dataType = "Boolean", paramType = "query", example = "true"),
        @ApiImplicitParam(name = "lineColor", value = "线条颜色，格式为R,G,B", dataType = "String", paramType = "query", example = "0,0,0"),
        @ApiImplicitParam(name = "isHyaline", value = "是否需要透明底色", dataType = "Boolean", paramType = "query", example = "false")
    })
    public ResponseEntity<Map<String, Object>> getWxacode(
            @RequestParam String page,
            @RequestParam String scene,
            @RequestParam(required = false) Integer width,
            @RequestParam(required = false) Boolean autoColor,
            @RequestParam(required = false) String lineColor,
            @RequestParam(required = false) Boolean isHyaline) {
        return wxMaService.getWxacode(page, scene, width, autoColor, lineColor, isHyaline);
    }
    
    /**
     * 获取小程序码（适用于需要的码数量极多的业务场景）
     */
    @GetMapping("/getwxacodeunlimit")
    @ApiOperation(value = "获取小程序码（无限制）", notes = "获取小程序码，适用于需要的码数量极多的业务场景")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "page", value = "跳转页面路径", required = true, dataType = "String", paramType = "query", example = "pages/index/index"),
        @ApiImplicitParam(name = "scene", value = "场景参数", required = true, dataType = "String", paramType = "query", example = "id=1&type=product"),
        @ApiImplicitParam(name = "width", value = "二维码宽度", dataType = "Integer", paramType = "query", example = "430"),
        @ApiImplicitParam(name = "autoColor", value = "自动配置线条颜色", dataType = "Boolean", paramType = "query", example = "true"),
        @ApiImplicitParam(name = "lineColor", value = "线条颜色，格式为R,G,B", dataType = "String", paramType = "query", example = "0,0,0"),
        @ApiImplicitParam(name = "isHyaline", value = "是否需要透明底色", dataType = "Boolean", paramType = "query", example = "false")
    })
    public ResponseEntity<Map<String, Object>> getWxacodeUnlimit(
            @RequestParam String page,
            @RequestParam String scene,
            @RequestParam(required = false) Integer width,
            @RequestParam(required = false) Boolean autoColor,
            @RequestParam(required = false) String lineColor,
            @RequestParam(required = false) Boolean isHyaline) {
        return wxMaService.getWxacodeUnlimit(page, scene, width, autoColor, lineColor, isHyaline);
    }
    
    /**
     * 获取小程序二维码（适用于需要的码数量较少的业务场景）
     */
    @GetMapping("/createwxaqrcode")
    @ApiOperation(value = "获取小程序二维码", notes = "获取小程序二维码，适用于需要的码数量较少的业务场景")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "path", value = "跳转页面路径", required = true, dataType = "String", paramType = "query", example = "pages/index/index?id=1&type=product"),
        @ApiImplicitParam(name = "width", value = "二维码宽度", dataType = "Integer", paramType = "query", example = "430")
    })
    public ResponseEntity<Map<String, Object>> createWxaQrcode(
            @RequestParam String path,
            @RequestParam(required = false) Integer width) {
        return wxMaService.createWxaQrcode(path, width);
    }
} 